/************************************************************************
 * @file AbstractPanelContainer.h
 * @author Ian Chen
 * @version 1.0
 *
 * @section LICENSE
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 3 of
 * the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
 * General Public License for more details at
 * http://www.gnu.org/licenses/lgpl.html
 *
 ************************************************************************/
#ifndef ABSTRACTPANELCONTAINER_H
#define ABSTRACTPANELCONTAINER_H

#include <vector>
using namespace std;

#include <QDockWidget>
#include <QFrame>

#include <pluginui/pluginui_global.h>

#include <pluginui/manager/PanelItem.h>

namespace antu
{
namespace plugin
{
namespace ui
{
/*!
 * \brief The AbstractPanelContainer class arranges
 *        layout for side panels as well as content windows.
 *
 */
class PLUGINUISHARED_EXPORT AbstractPanelContainer : public QObject
{
    Q_OBJECT

protected:
    Qt::DockWidgetAreas m_eAllowedAreas;
    Qt::DockWidgetArea  m_eInitialDockArea;
    QDockWidget::DockWidgetFeatures m_eFeatures;
    QString m_sName;
    bool     m_bOpenFloating;
    bool    m_bChangeWindowTitleWithTab;

    vector<PanelItem*> m_oPanelItems;

    void clear();

    void set(Qt::DockWidgetArea area = Qt::NoDockWidgetArea,
             Qt::DockWidgetAreas allowedAreas = Qt::LeftDockWidgetArea |
                                                Qt::RightDockWidgetArea |
                                                Qt::BottomDockWidgetArea,
             QDockWidget::DockWidgetFeatures features = QDockWidget::DockWidgetClosable |
                                                        QDockWidget::DockWidgetFloatable |
                                                        QDockWidget::DockWidgetMovable);

public:

    /*!
     * \brief AbstractPanelContainer
     * \param area
     * \param allowedAreas
     * \param features
     */
    AbstractPanelContainer(const QString& name,
                           Qt::DockWidgetArea area = Qt::NoDockWidgetArea,
                           Qt::DockWidgetAreas allowedAreas = Qt::LeftDockWidgetArea |
                                                              Qt::RightDockWidgetArea |
                                                              Qt::BottomDockWidgetArea,
                           QDockWidget::DockWidgetFeatures features = QDockWidget::DockWidgetClosable |
                                                                      QDockWidget::DockWidgetFloatable |
                                                                      QDockWidget::DockWidgetMovable);
    virtual ~AbstractPanelContainer();

    QString containerName() const;

    void addPanel(const QString& name, QWidget* pWidget, int stretch = 0);
    void addPanel(const QString& name, QWidget* pWidget, QMenu* pContextMenu, int stretch = 0);

    QStringList panelNames() const;

    Qt::DockWidgetArea dockArea() const;

    Qt::DockWidgetAreas allowedAreas() const;

    QDockWidget::DockWidgetFeatures features() const;

    bool isFloating() const;

    virtual void addSeparator(QFrame::Shadow shadow = QFrame::Sunken) = 0;

    PanelItem* operator[](const QString& panelName);

    virtual QWidget* containerWidget() = 0;

    void finalize();

    bool changeWindowTitleWithTab()
    {
        return this->m_bChangeWindowTitleWithTab;
    }

    virtual void setChangeWindowTitleWithTab(bool changeWithTab) = 0;

signals:
    void dockAreaChanged(Qt::DockWidgetArea newArea);
    void floatingStateChanged(bool isFloating);
    void visibilityChanged(bool visible);
    void tabChanged(QWidget* current);

protected:
    virtual void addToContainer(PanelItem* pPanelItem, int stretch = 0) = 0;

    virtual void doFinalize();
};
}
}
}

#endif // ABSTRACTPANELCONTAINER_H
